package com.tbit.main.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.log.OrderLogDao;
import com.tbit.main.pojo.OrderLog;
import com.tbit.main.service.OrderLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service("orderLogService")
public class OrderLogServiceImpl implements OrderLogService {

    @Autowired
    private OrderLogDao orderLogDao;

    @Override
    public void insert(OrderLog orderLog) {
        orderLogDao.insert(orderLog);
    }

    @Override
    public void insertBatch(List<OrderLog> orderLogs) {
        if (CollUtil.isNotEmpty(orderLogs)) {
            orderLogDao.insertBatch(orderLogs);
        }
    }

    @Override
    public void update(OrderLog orderLog) {
        orderLogDao.update(orderLog);
    }

    @Override
    public Integer queryCount(Integer accountId, Integer userMainId, String userCode, String startTime, String endTime, Integer opType) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("userMainId", userMainId);
        params.put("userCode", userCode);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        params.put("opType", opType);
        return orderLogDao.queryCount(params);
    }

    @Override
    public List<OrderLog> queryPage(Integer accountId, Integer userMainId, String userCode, String startTime, String endTime, Integer rowCount, Integer pageNO, Integer opType) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("userMainId", userMainId);
        params.put("userCode", userCode);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        params.put("start", (pageNO - 1) * rowCount);
        params.put("rowCount", rowCount);
        params.put("opType", opType);
        return orderLogDao.queryPage(params);
    }

    @Override
    public OrderLog getSerNO(String orderSerNo) {
        return orderLogDao.getSerNO(orderSerNo);
    }


}  